#pragma once

#include "xImgThread.h"
#include "ddraw.h"

//#define dkq_test_MJPEGDEC
#ifdef dkq_test_MJPEGDEC
#include "..\TGPublic\TGLogInfo.h"
#endif

#include "DDrawPrimary.h"


//#define SDK_IJL_JPEG 1
//#define SDK_LIBJPEG 1
#define SDK_CXIMAGEJPEG 1
//#define SDK_IJL15_JPEG 1

#if SDK_IJL15_JPEG
#include "JPEGDecoder.h"
#endif

class ImageMan : public xImgThread
{
public:
	ImageMan(void);
	~ImageMan(void);

public:
	int Initialize(HWND hWnd);
	int UnInitialize();

public:
	int InputImage(void *pImgFrame,long lImgSize);


private:
	virtual int Play_Image_Fun();

private:
	int  InputPic(BYTE *pPicBuffer,long lPicSize,unsigned char cType);
	int  InitDirectDraw(DWORD dwWidth,DWORD dwHeight);
	void UnInitDirectDraw();

private:
	BOOL  m_bWorking;
	long  m_lFrameBufSize;
	long  m_lFrameSize;
	BYTE *m_pFrameBuffer;

private:
	HWND  m_hWnd;
	DWORD m_dwWidth,m_dwHeight;

	int   m_nBufSize;
	BYTE *m_pBuffer;

private:
#if SDK_IJL15_JPEG
	CJPEGDecoder m_jpegDecoder;
#endif

private:
	//TGCriticalSection m_xSect;

private:
	LPDIRECTDRAWSURFACE7 m_pDDSBack;
	LPDIRECTDRAWCLIPPER  m_pcClipper;

	int                  m_nPixelSize;

#ifdef dkq_test_MJPEGDEC
public:
	TGLogInfo m_xLog;
#endif

};
